package com.xysoft.admin.common;

import java.util.List;

import com.xysoft.ServiceLocator;
import com.xysoft.admin.dao.IBaseDao;
import com.xysoft.model.Config;

@SuppressWarnings("unchecked")
public class ElementConst {
	private static IBaseDao baseDao;
	//组织等级类型
	public static final String LEVELTYPE = "1000";
	//最高级(顶级)
	public static final String ZEROLEVEL = "0";
	//校级(第一级)
	public static final String ONELEVEL = "00";
	
	//题目等级类型
	public static final String PROBLEMLEVETYPE = "2000";
	
	//用户图片存在路径
	public static final String USERPICPATH = "/file/pic/user";
	
	//初始化前台角色信息
	public static String ROLENAME = "评测角色";
	public static String ROLEREMARK = "评测平台上拥有的权限";
	
	//前台用户类型
	public static final String USERTYPE = "0001";
	public static final String USERTYPE_MEMBER = "0000";
	public static final String USERTYPE_STUDENT = "0001";
	public static final String USERTYPE_ACM = "0002";
	
	//题目测试数据路径
	public static String PROBLEMDATAPATH;
	//题目编译器路径
	public static String PROBLEMCOMPILEPATH;
	
	private static IBaseDao getBaseDao() {
    	if (baseDao == null) {
    		baseDao = ServiceLocator.getService(IBaseDao.class);
    	}
    	return baseDao;
    }
	
	static {
		List<Config> cfgs = getBaseDao().find("from Config");
		for (Config cfg : cfgs) {
			setValue(cfg.getKeyName(), cfg.getValue());
		}
	}
	
	public static void setValue(String name, String value) {
		if ("PROBLEMDATAPATH".equals(name)) {
			PROBLEMDATAPATH = value;
		} else if ("PROBLEMCOMPILEPATH".equals(name)) {
			PROBLEMCOMPILEPATH = value;
		}
	}
}
